home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / BatB.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  17.2 KB  |  593 lines

  1. class classes.enemy.BatB
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var matrixCoords;
  7.    var form;
  8.    var id;
  9.    var clip;
  10.    var colorR;
  11.    var trans;
  12.    var colorTrans;
  13.    var advanceMax;
  14.    var advanceMax2;
  15.    var matrixVar;
  16.    var dir;
  17.    var f2;
  18.    var axis;
  19.    var xDest;
  20.    var yDest;
  21.    var oldDir;
  22.    var xMov = 0;
  23.    var yMov = 0;
  24.    var xmt = 0;
  25.    var ymt = 0;
  26.    var xMovT = 0;
  27.    var yMovT = 0;
  28.    var speedOrig = 8;
  29.    var speed = 8;
  30.    var xDestMet = false;
  31.    var yDestMet = false;
  32.    var c = 0;
  33.    var feelerInfo = [[-400,0,400,40],[0,0,400,40],[0,-400,40,400],[0,0,40,400]];
  34.    var dirArray = ["L","R","U","D"];
  35.    var pUp = false;
  36.    var life = 4;
  37.    var nudging = false;
  38.    var nc = 0;
  39.    var xA = 0;
  40.    var yA = 0;
  41.    var power = 20;
  42.    var launchArray = [0,3,3,3,6,9,6,12,12,18,24,21,24];
  43.    var Name = "batB";
  44.    function BatB(px, py, pmoveScript, pmatrixCoords, pform, pid)
  45.    {
  46.       this.x = px;
  47.       this.y = py;
  48.       this.moveScript = pmoveScript.slice();
  49.       this.matrixCoords = pmatrixCoords.slice();
  50.       this.form = pform.slice();
  51.       this.id = pid;
  52.       _root.d = _root.d + 1;
  53.       this.clip = _root.attachMovie("batB","batB" + this.id + "Clip",_root.d + 50000);
  54.       this.clip._x = this.x;
  55.       this.clip._y = this.y;
  56.       this.colorR = _root.randRange(-30,30);
  57.       this.trans = new flash.geom.Transform(this.clip);
  58.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  59.       this.trans.colorTransform = this.colorTrans;
  60.       this.speed *= _root.dif.speed;
  61.       this.speedOrig = this.speed;
  62.       this.life *= _root.dif.life;
  63.       this.advanceMax = 60 / (this.speed / 2);
  64.       this.advanceMax2 = 50 / (this.speed / 2);
  65.       if(this.matrixCoords[0] == "free")
  66.       {
  67.          this.matrixVar = 0;
  68.       }
  69.       else
  70.       {
  71.          this.matrixVar = 1;
  72.       }
  73.       this.speedVar();
  74.       if(random(100) > 92)
  75.       {
  76.          this.pUp = true;
  77.       }
  78.       this.parseMoveScript();
  79.       _root.stats.created = _root.stats.created + 1;
  80.    }
  81.    function broBehind()
  82.    {
  83.       this.dir = _root.advanceDir;
  84.    }
  85.    function bombed(num)
  86.    {
  87.       this.f2 = "death";
  88.    }
  89.    function nudge(pxA, pyA, pscale)
  90.    {
  91.       this.nc = 0;
  92.       this.nudging = true;
  93.       var _loc2_ = pscale / 100;
  94.       this.xA = pxA * _loc2_;
  95.       this.yA = pyA * _loc2_;
  96.    }
  97.    function speedVar()
  98.    {
  99.       if(random(3) == 1)
  100.       {
  101.          this.speed *= _root.randRange2(0.9999,1.0001);
  102.       }
  103.    }
  104.    function twist()
  105.    {
  106.       this.clip.body.gotoAndPlay("twist");
  107.    }
  108.    function parseMoveScript()
  109.    {
  110.       this.dir = this.moveScript[0];
  111.       if(this.dir == "break")
  112.       {
  113.          delete this.moveScript;
  114.          this[this.axis + "MovT"] = 0;
  115.          if(this.matrixCoords[0] == "free")
  116.          {
  117.             this.f2 = "wander";
  118.             this.axis = random(10) <= 4 ? "y" : "x";
  119.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  120.             this.speedVar();
  121.             this.getDirString();
  122.          }
  123.          else
  124.          {
  125.             this.xDest = _root.advanceDir != "L" ? this.matrixCoords[0] * 60 : this.matrixCoords[0] * 60 + 320;
  126.             this.yDest = this.matrixCoords[1] * 50 + 10;
  127.             this.axis = Math.abs(this.xDest - this.x) <= Math.abs(this.yDest - this.y) ? "y" : "x";
  128.             this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  129.             this.getDirString();
  130.             this.speedVar();
  131.             this.f2 = "gotoMatrix";
  132.          }
  133.       }
  134.       else
  135.       {
  136.          this[this.axis + "MovT"] = 0;
  137.          this.f2 = "gotoXYDest";
  138.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  139.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  140.          this.speedVar();
  141.          if(this.dir == "L" || this.dir == "U")
  142.          {
  143.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  144.          }
  145.          else
  146.          {
  147.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  148.          }
  149.          this.moveScript.splice(0,2);
  150.       }
  151.    }
  152.    function gotoXYDest()
  153.    {
  154.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  155.       {
  156.          if(this.axis == "x")
  157.          {
  158.             this.x = this.xDest;
  159.          }
  160.          else
  161.          {
  162.             this.y = this.yDest;
  163.          }
  164.          this.parseMoveScript();
  165.       }
  166.    }
  167.    function gotoMatrix()
  168.    {
  169.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  170.       {
  171.          if(this.axis == "x")
  172.          {
  173.             this.x = this.xDest;
  174.          }
  175.          else
  176.          {
  177.             this.y = this.yDest;
  178.          }
  179.          this[this.axis + "MovT"] = 0;
  180.          this.axis = this.axis != "x" ? "x" : "y";
  181.          this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  182.          this.getDirString();
  183.          this.speed = this.speedOrig;
  184.       }
  185.       if(Math.abs(this.x - this.xDest) < this.speed + 1 && Math.abs(this.y - this.yDest) < this.speed + 1)
  186.       {
  187.          this.x = this.clip._x = this.xDest;
  188.          this.y = this.clip._y = this.yDest;
  189.          this.xMovT = this.xMov = 0;
  190.          this.yMovT = this.yMov = 0;
  191.          this.matrixVar = 2;
  192.          this.dir = _root.advanceDir;
  193.          _root.matrixNum = _root.matrixNum + 1;
  194.          if(_root.matrixNum >= _root.matrixSize)
  195.          {
  196.             _root.matrixComplete = true;
  197.          }
  198.          _root["formB" + this.form[0]] = "matrixed";
  199.          this.f2 = "wait";
  200.       }
  201.    }
  202.    function getDirString()
  203.    {
  204.       if(this.xMovT < -1)
  205.       {
  206.          this.dir = "L";
  207.       }
  208.       else if(this.xMovT > 1)
  209.       {
  210.          this.dir = "R";
  211.       }
  212.       else if(this.yMovT > 1)
  213.       {
  214.          this.dir = "D";
  215.       }
  216.       else if(this.yMovT < -1)
  217.       {
  218.          this.dir = "U";
  219.       }
  220.    }
  221.    function wait()
  222.    {
  223.       if(random(1000) >= 998 + _root.dif.wait && _root.matrixComplete)
  224.       {
  225.          this.dir = this.findDir();
  226.          if(this.dir == _root.advanceDir)
  227.          {
  228.             this.matrixVar = 0;
  229.             this.clip.body.gotoAndPlay("spread");
  230.             if(random(2) == 1)
  231.             {
  232.                this.xMovT = 0;
  233.                this.power = 30;
  234.                this.f2 = "launching";
  235.                this.c = 0;
  236.             }
  237.             else
  238.             {
  239.                this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  240.                this.f2 = "attacking";
  241.             }
  242.          }
  243.          else if(this.dir == "U" || this.dir == "D")
  244.          {
  245.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  246.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  247.             this.matrixVar = 0;
  248.             this.c = 0;
  249.             this.f2 = "leavingMatrix";
  250.          }
  251.       }
  252.    }
  253.    function evade()
  254.    {
  255.       if(this.matrixVar == 2)
  256.       {
  257.          this.matrixVar = 0;
  258.          if(random(2) == 1)
  259.          {
  260.             this.f2 = "wander";
  261.             this[this.axis + "MovT"] = 0;
  262.             this.axis = random(10) <= 4 ? "y" : "x";
  263.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  264.             this.speedVar();
  265.             this.getDirString();
  266.          }
  267.          else
  268.          {
  269.             this.clip.body.gotoAndPlay("spread");
  270.             this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  271.             this.f2 = "attacking";
  272.          }
  273.       }
  274.    }
  275.    function launching()
  276.    {
  277.       this.c = this.c + 1;
  278.       if(this.c == 7)
  279.       {
  280.          this.clip.body.gotoAndPlay("launch");
  281.          _root.audio.playLevel3("batLaunch",_root.randRange(10,20));
  282.       }
  283.       if(this.c > 7 && this.c < 21)
  284.       {
  285.          this.x = _root.advanceDir != "L" ? this.x + this.launchArray[this.c - 8] : this.x - this.launchArray[this.c - 8];
  286.       }
  287.       if(this.c == 21)
  288.       {
  289.          this.xMovT = _root.advanceDir != "L" ? 25 : -25;
  290.          this.xMov = _root.advanceDir != "L" ? 25 : -25;
  291.          this.f2 = "attacking2";
  292.       }
  293.    }
  294.    function leavingMatrix()
  295.    {
  296.       this.c = this.c + 1;
  297.       if(this.c > this.advanceMax2)
  298.       {
  299.          this.c = 0;
  300.          this.dir = this.findDir();
  301.          if(this.dir == _root.advanceDir)
  302.          {
  303.             this.yMovT = 0;
  304.             this.clip.body.gotoAndPlay("spread");
  305.             if(random(2) == 1)
  306.             {
  307.                this.xMovT = 0;
  308.                this.f2 = "launching";
  309.                this.c = 0;
  310.             }
  311.             else
  312.             {
  313.                this.xMovT = _root.advanceDir != "L" ? this.speed : -1 * this.speed;
  314.                this.f2 = "attacking";
  315.             }
  316.          }
  317.       }
  318.    }
  319.    function findDir()
  320.    {
  321.       _root.d = _root.d + 1;
  322.       _root.attachMovie("feeler","feelerClip",_root.d);
  323.       var _loc7_ = [];
  324.       var _loc9_ = 0;
  325.       var _loc11_ = this.dirArray.length;
  326.       while(_loc9_ < _loc11_)
  327.       {
  328.          _root.feelerClip._x = this.x + this.feelerInfo[_loc9_][0];
  329.          _root.feelerClip._y = this.y + this.feelerInfo[_loc9_][1];
  330.          _root.feelerClip._width = this.feelerInfo[_loc9_][2];
  331.          _root.feelerClip._height = this.feelerInfo[_loc9_][3];
  332.          var _loc3_ = 0;
  333.          var _loc8_ = _root.chars.length;
  334.          var _loc6_ = false;
  335.          while(_loc3_ < _loc8_)
  336.          {
  337.             var _loc5_ = _root.chars[_loc3_] + "Clip";
  338.             if(_root.feelerClip.hitTest(_root[_loc5_]))
  339.             {
  340.                var _loc4_ = _root.chars[_loc3_];
  341.                if(_root[_loc4_].matrixVar == 2 && _loc4_ != this.Name + this.id)
  342.                {
  343.                   _loc6_ = true;
  344.                   break;
  345.                }
  346.             }
  347.             _loc3_ = _loc3_ + 1;
  348.          }
  349.          if(!_loc6_)
  350.          {
  351.             var _loc10_ = _root.advanceDir != "L" ? "L" : "R";
  352.             if(this.dirArray[_loc9_] != _loc10_)
  353.             {
  354.                _loc7_.push(this.dirArray[_loc9_]);
  355.             }
  356.          }
  357.          _loc9_ = _loc9_ + 1;
  358.       }
  359.       _loc9_ = 0;
  360.       _loc11_ = _loc7_.length;
  361.       if(_loc9_ < _loc11_)
  362.       {
  363.          if(_loc7_[_loc9_] == _root.advanceDir)
  364.          {
  365.             return _root.advanceDir;
  366.          }
  367.          return _loc7_[random(_loc7_.length)];
  368.       }
  369.    }
  370.    function attacking()
  371.    {
  372.       this.xMovT *= 1.03;
  373.       this.yMovT *= 1.03;
  374.    }
  375.    function attacking2()
  376.    {
  377.       this.xMovT *= 1.015;
  378.       this.yMovT *= 1.015;
  379.    }
  380.    function death()
  381.    {
  382.       _root.stats.destroyed = _root.stats.destroyed + 1;
  383.       _root.stats.score += 1000;
  384.       _root.powerUp(this.x,this.y,95);
  385.       if(this.matrixVar == 1)
  386.       {
  387.          _root.matrixNum = _root.matrixNum + 1;
  388.          if(_root.matrixNum >= _root.matrixSize)
  389.          {
  390.             _root.matrixComplete = true;
  391.          }
  392.       }
  393.       var _loc3_ = 0;
  394.       var _loc4_ = _root["form" + this.form[0]].length;
  395.       while(_loc3_ < _loc4_)
  396.       {
  397.          if(_root["form" + this.form[0]][_loc3_] == "batB" + this.id)
  398.          {
  399.             _root["form" + this.form[0]].splice(_loc3_,1);
  400.             if(_root["form" + this.form[0]].length == 0)
  401.             {
  402.                delete _root["form" + this.form[0]];
  403.                if(_root["formB" + this.form[0]] == "matrixed")
  404.                {
  405.                   _loc3_ = 0;
  406.                   _loc4_ = random(3) + 1;
  407.                   while(_loc3_ < _loc4_)
  408.                   {
  409.                      _root.createPowerUp([this.x,this.y,"coin1"]);
  410.                      _loc3_ = _loc3_ + 1;
  411.                   }
  412.                   _root.stats.score += 1000;
  413.                }
  414.                else
  415.                {
  416.                   _root.createPowerUp([this.x,this.y,"coin5"]);
  417.                   _root.stats.score += 2000;
  418.                }
  419.                delete _root["formB" + this.form[0]];
  420.             }
  421.             break;
  422.          }
  423.          _loc3_ = _loc3_ + 1;
  424.       }
  425.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(80,130),_root.randRange(75,100),"Red"]);
  426.       var _loc5_ = 0;
  427.       var _loc6_ = random(3);
  428.       while(_loc5_ < _loc6_)
  429.       {
  430.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"batB","Red"]);
  431.          _loc5_ = _loc5_ + 1;
  432.       }
  433.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"red"]);
  434.       _root.audio.playLevel4("batX" + (random(2) + 1),_root.randRange(8,15));
  435.       _root.removeChar("batB" + this.id);
  436.       this.f2 = "";
  437.    }
  438.    function death2()
  439.    {
  440.       _root.removeChar("batB" + this.id);
  441.       this.f2 = "";
  442.    }
  443.    function advance()
  444.    {
  445.       this.dir = _root.advanceDir;
  446.       this.clip.body.gotoAndPlay("advance");
  447.       this.xMovT = _root.advanceDir != "L" ? 1 * (this.speed / 2) : -1 * (this.speed / 2);
  448.       this.f2 = "advancing";
  449.    }
  450.    function advancing()
  451.    {
  452.       this.c = this.c + 1;
  453.       if(this.c > this.advanceMax)
  454.       {
  455.          this.xMovT = 0;
  456.          this.c = 0;
  457.          this.f2 = "wait";
  458.          _root.d = _root.d + 1;
  459.          _root.attachMovie("sight","sightClip",_root.d);
  460.          _root.sightClip.gotoAndStop("hindSight");
  461.          _root.sightClip._x = this.x;
  462.          _root.sightClip._y = this.y;
  463.          if(_root.advanceDir == "L")
  464.          {
  465.             _root.sightClip._rotation = 180;
  466.          }
  467.          if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  468.          {
  469.             _root.broBehind();
  470.          }
  471.          removeMovieClip(_root.sightClip);
  472.       }
  473.    }
  474.    function wander()
  475.    {
  476.       if(random(100) > 96 + _root.dif.wander)
  477.       {
  478.          this[this.axis + "MovT"] = 0;
  479.          this.axis = this.axis != "x" ? "x" : "y";
  480.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  481.          this.getDirString();
  482.       }
  483.    }
  484.    function main()
  485.    {
  486.       this[this.f2]();
  487.       if(this.oldDir != this.dir)
  488.       {
  489.          this.clip.gotoAndStop("fly" + this.dir);
  490.       }
  491.       this.oldDir = this.dir;
  492.       if(this.nudging)
  493.       {
  494.          this.xA *= 0.5;
  495.          this.yA *= 0.5;
  496.          this.nc = this.nc + 1;
  497.          var _loc8_ = 255 - this.nc * 17;
  498.          this.colorTrans.redOffset = _loc8_;
  499.          this.colorTrans.greenOffset = _loc8_;
  500.          this.colorTrans.blueOffset = _loc8_;
  501.          this.trans.colorTransform = this.colorTrans;
  502.          if(this.nc == 15)
  503.          {
  504.             this.xA = this.yA = 0;
  505.             this.nudging = false;
  506.             this.colorTrans.redOffset = this.colorR;
  507.             this.colorTrans.greenOffset = this.colorR;
  508.             this.colorTrans.blueOffset = this.colorR;
  509.             this.trans.colorTransform = this.colorTrans;
  510.          }
  511.       }
  512.       var _loc4_ = 0;
  513.       var _loc7_ = _root.broShots.length;
  514.       while(_loc4_ < _loc7_)
  515.       {
  516.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  517.          if(this.clip.hitTest(_root[_loc6_]))
  518.          {
  519.             var _loc3_ = _root.broShots[_loc4_];
  520.             var _loc5_ = this.life;
  521.             this.life -= _root[_loc3_].power;
  522.             if(this.life < 1)
  523.             {
  524.                this.f2 = "death";
  525.             }
  526.             else
  527.             {
  528.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  529.                _root.audio.playLevel4("batHit" + (random(2) + 1),_root.randRange(10,20));
  530.             }
  531.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  532.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  533.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  534.             _root[_loc3_].hit(_loc5_);
  535.             break;
  536.          }
  537.          _loc4_ = _loc4_ + 1;
  538.       }
  539.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  540.       {
  541.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  542.          this.f2 = "death";
  543.       }
  544.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  545.       {
  546.          delete _root["form" + this.form[0]];
  547.          delete _root["formB" + this.form[0]];
  548.          this.f2 = "death2";
  549.       }
  550.       if(this.xMovT < this.xMov)
  551.       {
  552.          this.xMov -= 1;
  553.       }
  554.       else if(this.xMovT > this.xMov)
  555.       {
  556.          this.xMov += 1;
  557.       }
  558.       else
  559.       {
  560.          this.xMov = this.xMovT;
  561.       }
  562.       if(this.yMovT < this.yMov)
  563.       {
  564.          this.yMov -= 1;
  565.       }
  566.       else if(this.yMovT > this.yMov)
  567.       {
  568.          this.yMov += 1;
  569.       }
  570.       else
  571.       {
  572.          this.yMov = this.yMovT;
  573.       }
  574.       this.xmt = this.xMov;
  575.       this.ymt = this.yMov;
  576.       if(random(10) == 1)
  577.       {
  578.          if(this.axis == "y")
  579.          {
  580.             this.xmt += _root.randRange2(-1,1);
  581.          }
  582.          else
  583.          {
  584.             this.ymt += _root.randRange2(-1,1);
  585.          }
  586.       }
  587.       this.x += this.xmt + this.xA;
  588.       this.y += this.ymt + this.yA;
  589.       this.clip._x = this.x;
  590.       this.clip._y = this.y;
  591.    }
  592. }
  593.